# -*- coding: utf-8 -*-
import scrapy,re
from scrapy.http.cookies import CookieJar

class CgSpider(scrapy.Spider):
    name = 'cg'
    allowed_domains = ['cg.zhangsiming.com']
    start_urls = ['http://cg.zhangsiming.com/']
    cookie_jar = CookieJar()

    def parse(self, response):
        pass
    def start_requests(self):
        with open('cookies_1.txt', 'r') as f:
            cookiejar = f.read()
            p = re.compile(r'<Cookie (.*?) for .*?>')
            cookies = re.findall(p, cookiejar)
            cookies = (cookie.split('=', 1) for cookie in cookies)
            cookies = dict(cookies)
        print(cookies)
        url="http://cg.zhangsiming.com/admin.php?c=index"#后台管理页面
        return [scrapy.Request(url=url,cookies=cookies,callback=self.login)]

    def login(self,response):
        print(response.text)

